package labox.innovation.gameserver.network.serverpackets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javolution.util.FastList;
import labox.innovation.config.Config;
import labox.innovation.gameserver.model.L2ItemInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;

/**
 * �·�������Ʒ�б�
 * 0x53 WareHouseDepositList  dh (h dddhh dhhh d)
 *
 * @version $Revision: 1.4.2.1.2.4 $ $Date: 2005/03/27 15:29:39 $
 */
public final class WareHouseDepositList extends L2GameServerPacket {
	
	public static final int PRIVATE = 1;

	public static final int CLAN = 4;

	public static final int CASTLE = 3; //not sure

	public static final int FREIGHT = 1;

	private static Logger _log = LoggerFactory.getLogger(WareHouseDepositList.class.getName());

	private static final String _S__53_WAREHOUSEDEPOSITLIST = "[S] 41 WareHouseDepositList";

	private final long _playerAdena;

	private final FastList<L2ItemInstance> _items;

	private final int _whType;

	public WareHouseDepositList(FuzePcInstance player, int type) {
		_whType = type;
		_playerAdena = player.getMoneySilver();
		_items = new FastList<L2ItemInstance>();
		final boolean isPrivate = _whType == PRIVATE;

		for (L2ItemInstance temp : player.getInventory().getAvailableItems(true, isPrivate)) {
			if (temp != null && temp.isDepositable())
				_items.add(temp);
		}
	}

	@Override
	protected final void writeImpl() {
		writeByte(0x41);
		/* 0x01-Private Warehouse
		* 0x02-Clan Warehouse
		* 0x03-Castle Warehouse
		* 0x04-Warehouse */
		writeInt(_whType);
		writeLong(_playerAdena);
		final int count = _items.size();
		if (_log.isDebugEnabled())
			_log.debug("count:" + count, Config.SERVER_ID, "�·�������Ʒ�б�");
		writeInt(count);

		for (L2ItemInstance item : _items) {
			writeInt(item.getItem().getType1());
			writeLong(item.getObjectId());
			writeInt(item.getItemId());
			writeInt(item.getCount());
			writeInt(item.getItem().getType2());
			writeInt(item.getCustomType1());
			writeInt(item.getItem().getBodyPart());
			writeInt(item.getEnchantLevel());
			writeInt(item.getCustomType2());
			writeInt(item.getMana());
			writeInt(item.isTimeLimitedItem() ? (int) (item.getRemainingTime() / 1000) : -1);
		}
		_items.clear();
	}

	/* (non-Javadoc)
	 * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
	 */
	@Override
	public String getType() {
		return _S__53_WAREHOUSEDEPOSITLIST;
	}
}
